var product_obj={
		product_add:function(){
			//成团类型添加
			$('#chengtuan_table .input_add2').click(function(){	
				var num=$('#chengtuan_table tr[FieldType=text]').eq(-1).attr('mid');
				num = parseInt(num)+parseInt("1");
				var html='';
				html+='<tr style="display:;" fieldtype="text" mid="'+num+'">'
				html+='<td>成团类型'+num+'：</td>'
				html+='<td><input type="text" class="form_input" value="" name="chengtuan[]"></td>'
				html+='<td><input type="text" class="form_input" value="" name="chengtuanprice[]"></td>'
				html+='<td>'
				html+='<a href="javascript:void(0);" class="input_del2"><img src="'+domain.static+'/Public/Member/images/ico/del.gif"></a>'
				html+='</td>'
				html+'</tr>'
				
				$('#chengtuan_table #chengtuan').append(html);
			});
			
			//成团类型删除
			$('#chengtuan_table .input_del2').live("click",function(){	
				$('#chengtuan_table .input_add2').show();
				$(this).parent().parent().remove();
			});
//			
			//规格添加
			if(id != ""){
				$('#guige_table .input_add').click(function(){	
					var num=$('#guige_table tr[FieldType=text]').eq(-1).attr('mid');
					num = parseInt(num)+parseInt("1");
					var html='';
					html+='<tr style="display:;" fieldtype="text" mid="'+num+'">'
					html+='<td>规格'+num+'：</td>'
					html+='<td><input type="text" class="form_input" value="" name="guige[]"></td>'
					html+='<td><input type="text" class="form_input" value="" name="total[]"></td>'
					html+='<td><input type="text" class="form_input" value="" name="rest[]"></td>'
					html+='<td>'
					html+='<a href="javascript:void(0);" class="input_del"><img src="'+domain.static+'/Public/Member/images/ico/del.gif"></a>'
					html+='</td>'
					html+'</tr>'
					
					$('#guige_table #guige').append(html);
				});
			}else{
				$('#guige_table .input_add').click(function(){	
					var num=$('#guige_table tr[FieldType=text]').eq(-1).attr('mid');
					num = parseInt(num)+parseInt("1");
					var html='';
					html+='<tr style="display:;" fieldtype="text" mid="'+num+'">'
					html+='<td>规格'+num+'：</td>'
					html+='<td><input type="text" class="form_input" value="" name="guige[]"></td>'
					html+='<td><input type="text" class="form_input" value="" name="total[]"></td>'
					html+='<td>'
					html+='<a href="javascript:void(0);" class="input_del"><img src="'+domain.static+'/Public/Member/images/ico/del.gif"></a>'
					html+='</td>'
					html+'</tr>'
					
					$('#guige_table #guige').append(html);
				});
			}
			
			
			//规格删除
			$('#guige_table .input_del').live("click",function(){	
				$('#guige_table .input_add').show();
				$(this).parent().parent().remove();
			});
			
			//上传封面图片
			global_obj.file_upload($('#ImgUpload'), $('#product_form input[name=ImgPath]'), $('#ImgDetail'));
			$('#ImgDetail').html(global_obj.img_link($('#product_form input[name=ImgPath]').val()));
			
			//轮播图
			$('#PicDetail div span').on('click', function(){$(this).parent().remove();});
			var pic_count=parseInt($('#pic_count').html());
			var callback=function(imgpath){
				if($('#PicDetail div').size()>=pic_count){
					alert('您上传的图片数量已经超过5张，不能再上传！');
					return;
				}
				$('#PicDetail').append('<div>'+global_obj.img_link(imgpath)+'<span>删除</span><input type="hidden" name="PicPath[]" value="'+imgpath+'" /></div>');
				$('#PicDetail div span').off('click').on('click', function(){$(this).parent().remove();});
			};
			
			global_obj.file_upload($('#PicUpload'), '', '', 'shop_products', true, pic_count, callback);
			
			$(".btn_green").click(function(){
				if(global_obj.check_form($('*[notnull]'))){return false};
				$(this).attr('disabled', true)
				var remark=$('input[name=remark]').val();
				if(remark.length>10){
					alert("右侧备注不能超过10个字");
					return ;
				}
				var content= $("textarea[name=description]").val();
//				alert(content);
				$.post("?s=/Pintuan/add_product",$("#product_form").serialize()+'&description='+content,function(data){
					if(data.ret==1){
						alert('保存成功');
						window.location.href="?s=/Pintuan/list_product";
					}else{
						alert('保存失败');
						window.location.href="?s=/Pintuan/add_product/id/"+data.id;
					}
				});
			});
		},

		//商品列表页
		product_list:function(){
			//时间插件
			$('#search_form input[name=Time]').daterangepicker();
		},
		
		//购物流程
		product_liucheng:function(){
			
			$("#liucheng_form input[name=submit_button]").click(function(){
				var expiredtime = $('input[name=expiredtime]').val();
				if(expiredtime<0||expiredtime>24){
					alert("请按要求填写过期时间");
					return false;
				}
				var content= $("textarea[name=description]").val();
//				alert(content);
				if(content==""){
					alert("内容不能为空！");
					return false;
				}
				
				$.post("?s=/Pintuan/add_update",$("#liucheng_form").serialize(),function(data){
//					alert(data.msg);
					if(data.ret==1){
						alert(data.msg);
						window.location.href="?s=/Pintuan/liucheng";
					}else{
						alert(data.msg);
						window.location.href="?s=/Pintuan/liucheng";
					}
				});

			});
		},
		
		//订单列表
		product_order:function(){
			//时间插件
			$('#search_form input[name=Time]').daterangepicker();
		},
		
		//订单详细
		product_info:function(){
			$('#orders .cp_title #cp_view, #orders .cp_title #cp_mod').click(function(){
				$('#orders .cp_title div').removeClass('cur');
				$(this).addClass('cur');
				
				if($(this).attr('id')=='cp_view'){
					$('#orders_mod_form .cp_item_view').show();
					$('#orders_mod_form .cp_item_mod').hide();
				}else{
					$('#orders_mod_form .cp_item_view').hide();
					$('#orders_mod_form .cp_item_mod').show();
				}
			});
			
			$('#orders_mod_form .cp_item_mod .back').click(function(){$('#orders .cp_title #cp_view').click();});
		},
		
		//成团列表
		product_tuan:function(){
			//时间插件
			$('#search_form input[name=Time]').daterangepicker();
			//去发货
			$(".last a[href=#]").click(function(){
				var id=$(".last a[href=#]").attr('id');
				$.post("?s=/Pintuan/send","id="+id,function(data){
					if(data.ret==1){
//						alert(data.msg.length);
						alert('发货成功');
						window.location.href="?s=/Pintuan/list_tuan";
					}else{
						alert(data.msg);
					}
				});
			});
		},

			
		//退款列表
		list_tui:function(){
			//时间插件
			$('#search_form input[name=Time]').daterangepicker();
		},
		
		//退款详情
		detail_tui:function(){
			$('#orders .cp_title #cp_view, #orders .cp_title #cp_mod').click(function(){
				$('#orders .cp_title div').removeClass('cur');
				$(this).addClass('cur');
				
				if($(this).attr('id')=='cp_view'){
					$('#tui_form .cp_item_view').show();
					$('#tui_form .cp_item_mod').hide();
				}else{
					$('#tui_form .cp_item_view').hide();
					$('#tui_form .cp_item_mod').show();
				}
			});
			$('#tui_form .cp_item_mod .back').click(function(){$('#orders .cp_title #cp_view').click();});
			
			$("input[name=submit_button]").click(function(){
				$.post("?s=/Pintuan/action_tui",$("#tui_form").serialize(),function(data){
//					alert(data.ret);
					if(data.ret==1){
						alert('操作成功');
						window.location.href="?s=/Pintuan/list_tui";
					}else{
						alert('操作未能完成');
//						window.location.reload();
					}
				});
			});
		}
}







